< previous page page_483 next page >

Page 483
z0503-01.gif
Figure 14.12
Line segments are hidden where they
lie between the hi and lo values.
Figure 14.12 shows a line segment and the lo and hi values already displayed. In this case, you would draw the two end portions of the segment, where the segment does not lie between the hi and lo values. The part of the segment that you should not draw is shown with a dashed line in Figure 14.12. Note that the segment could be completely visible or completely obscured, or it could have several visible and hidden regions, depending on the particular segment and the values in the hi and lo arrays.
Implementing the Hi-Lo Algorithm
The following code implements the Hi-Lo algorithm. Subroutine DrawWithoutHidden controls the operation. It begins by calling subroutine DrawAndSetLine to draw the front edges of the surface.
Subroutine DrawAndSetLine draws the edges of the surface without checking the hi and lo arrays. It also initializes those arrays so that the hi and lo values equal the values displayed by the routine.
After drawing the front edges, DrawWithoutHidden uses subroutine DrawLine to draw the rest of the segments that make up the surface. DrawLine uses the hi and lo arrays to draw the visible portions of line segments. When it draws parts of a line, it updates the hi and lo arrays.
e10a6a0a59f035e870d90cca05b85fce.gif
' Draw the grid without hidden surfaces using the
' Hi-Lo algorithm.
Public Sub DrawWithoutHidden(ByVal pic As Object, _
    Optional R As Variant)
Dim Xmin As Integer
Dim Xmax As Integer
Dim lo() As Integer
Dim hi() As Integer
Dim ix As Integer
Dim i As Integer
Dim j As Integer

 
< previous page page_483 next page >